import request from '@/utils/request'
import type {
  AclUserResponseData,
  AclUser,
  AllRolesResponseData,
  AssignRole,
} from './type'
enum API {
  GETACLUSER_URL = '/admin/acl/user/',
  ADDACLUSER_URL = '/admin/acl/user/save',
  UPDATEACLUSER_URL = '/admin/acl/user/update',
  ALLROLE_URL = '/admin/acl/user/toAssign/',
}

export const reqGetAclUser = (page: number, limit: number,username:string) =>
  request.get<any, AclUserResponseData>(API.GETACLUSER_URL + `${page}/${limit}?username=${username}`)

export const reqAddOrUpdateAclUser = (data: AclUser) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEACLUSER_URL, data)
  } else {
    return request.post<any, any>(API.ADDACLUSER_URL, data)
  }
}

export const reqAllRole = (adminId: number) => {
  return request.get<any, AllRolesResponseData>(API.ALLROLE_URL + adminId)
}

export const reqAssignRole = (data: AssignRole) => {
  return request.post<any, any>('/admin/acl/user/doAssignRole', data)
}

export const reqDeleteAclUser = (idList: number[]) =>
  request.delete<any, any>('/admin/acl/user/batchRemove', { data: idList })

export const reqDeleteAclUserById = (id: number) =>
  request.delete<any, any>('/admin/acl/user/remove/' + id)
